new Vue({
  el: '#app',
  data() {
    return {
      form: {
        page: 1,			//页数
        limit: 10,		//每页数据条数
        Role_Name: ''	,	//角色名称
        Role_Id: '',
        Role_Status:''
      },
      formData: {},
      total: 0,
      tableData: [],		//表格数据
      dialogTableVisible: false,
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    onSerach() {				//查询方法
      this.getList(this.form)
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    tableCellStyle({ row, column, rowIndex, columnIndex }) {
      if (row.Admin_Type == '2') return { backgroundColor: 'yellowgreen' }
    },
    getList() {
      console.log('11', 11);
      const _this = this
      $.ajax({
        type: 'GET',
        url: BASE_URL+'/weixin/getRoleInfo',
        //   data,
        success: function (res) {
          console.log('res', res);
          // if (res.Status == 'success') {
          console.log('角色', res);
          // res.tableData.unshift(...res.tableData.splice(res.tableData.findIndex(i => i.Admin_Type == '2'),1));
          _this.tableData = res.data
          // _this.total = parseInt(res.limit)
          // }
        },
        error: function (res) {
          console.log('错误', res);
          _this.$message.error("操作失败，请稍后再试");
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    addEnterprise() {
      window.location.href = './Add.html?token=' + $.cookie("token")
    },
    editMember(row) {
      sessionStorage.setItem("Role_Name", row.Role_Name);
      sessionStorage.setItem("Role_Id", row.Role_Id);
      window.location.href = './Edit.html'; // Redirect to Edit.html
    },
    handleMenu(User_Number) {
      sessionStorage.setItem("User_Number", User_Number)
      window.location.href = './Menu.html?User_Number=' + User_Number
    },
    handleExamine(User_Number) {
      const this_ = this
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getInquiryIDOriginal?token=${$.cookie("token")}`,
        data: {
          Primary_Key_Name: 'User_Number',
          Primary_Key: User_Number,
          Data: 'system_user_info',
        },
        success: function (Result) {
          console.log(Result)
          this_.formData = Result[0]
          this_.dialogTableVisible = true
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    UpdateApplication(i) {
      const this_ = this
      this_.formData.Examine = i
      if (i == 0) {
        this_.formData.Authentication = 1
      }
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getEditAction?token=${$.cookie("token")}`,
        data: {
          Data: JSON.stringify(
            {
              Modify: { 'system_user_info': [this_.formData] },
            }
          )
        },
        success: function (Result) {
          console.log(Result)
          if (Result.Status == 'success' && i == 2) {
            this_.$message({
              message: '已拒绝对方申请',
              type: 'warning'
            });
            this_.dialogTableVisible = false
            this_.getList(this_.form)
          } else if (Result.Status == 'success' && i == 0) {
            this_.$message({
              message: '已同意对方申请',
              type: 'success'
            });
            sessionStorage.setItem("User_Number", this_.formData.User_Number)
            window.location.href = './Menu.html?User_Number=' + this_.formData.User_Number
          } else {
            this_.$message({
              message: '系统异常,请稍后重试',
              type: 'error'
            });
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    handleEdit(EnterpriseInfo_SerialNumber) {
      sessionStorage.setItem("EnterpriseInfo_SerialNumber", EnterpriseInfo_SerialNumber)
      window.location.href = './Edit.html?EnterpriseInfo_SerialNumber=' + EnterpriseInfo_SerialNumber
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //点击按钮
    deletMember(row) {
      const _this = this;
      this.$confirm('此操作将删除该信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        _this.Delete(row);
      }).catch(() => {
        this.$message({
          type: 'warning',
          message: '已取消删除'
        });
      });
    },
    //删除
    Delete(row) {
      const _this = this;
      $.ajax({
        url: BASE_URL+'/weixin/deleteRoleInfo',
        type: 'POST',
        data:{
          role_id: row.Role_Id
        },
        error: function (res) {
          console.log(res);
          _this.$message.error("删除失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (res) {
          console.log('删除',res);
          if (res == 'success') {
            _this.$message({
              type: 'success',
              message: '删除成功!'
            });
            _this.getList()
          }
        }
      })
    },
  },
})